package org.seed.quantum.example.udp;

import org.seed.quantum.protocol.StringProtocol;
import org.seed.quantum.protocol.udp.UdpBootstrap;

import java.io.IOException;

public class UdpServerDemo {

    public static void main(String[] args) throws IOException {
        UdpBootstrap bootstrap = new UdpBootstrap(new StringProtocol(), (session, msg) -> {
            System.out.println("收到客户端消息: " + msg);
            byte[] bytes = msg.getBytes();
            try {
                session.writeBuffer().writeInt(bytes.length);
                session.writeBuffer().write(bytes);
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
        bootstrap.setThreadNum(Runtime.getRuntime().availableProcessors())
                .setReadBufferSize(1024).open(8887);
    }


}
